﻿
/**
*@description 上传附件表单
*/
Chenxin.UI.UploadHeadPicForm=Chenxin.extend(Chenxin.UI.FormCommon,{	
	actionUrl:'/service/UploadHeadPic.ashx',
	id:'uploadheadpic',
	renderTo:'uploadheadpicWin',
	jqmWidth:550,
	createForm:function(){
		return Chenxin.FormCommon.UploadHeadPicForm(this.id);
	},
    initEvent: function() {
		var _this=this;
		var thisid='#'+this.id;	
		_this.isclick = true;
		
		$(thisid+'_cancle').live('click',function(){			
			_this.hide();
		});
		
		//上传附件Flash
        $("#UpHeadPic").uploadify({
            uploader: '/js/uploadify.swf',
            script: '/service/UploadHeadPic.ashx?op=fileupload',
            cancelImg: '/images/cancel.png',
            buttonImg:'/images/fileupload.png', 
            auto: true,
            multi: false,
            sizeLimit: 1048576,
            height: 24,
            width: 190,
            fileDesc: '支持格式:jpg,gif,png',  
            fileExt: '*.jpg;*.gif;*.png', 
            wmode:'transparent',
            onComplete: function(event, queueID, fileObj, response, data) {
                if(response){
					try{					
						eval("var json="+response);
						if(json.success==1){
							if(data.fileCount==0){
							    window.parent.buildAvatarEditor(""+json.data.picid+"",""+json.data.picurl+"","photo"); 
							} 
						}else if(json.success==0){
							alert(json.msg);
						}else{
							alert(json.msg);
							window.location.href=Chenxin.loginUrl;
			            }
			       	}catch(e){
						alert('返回数据格式错误，文件上传失败！');
					}
				}
            },
            onError: function(event, queueID, fileObj, errorObj) {
                alert("文件:" + fileObj.name + "上传失败("+errorObj.info+")");
            }
        });

    },
	initComponent:function(){
		Chenxin.UI.UploadHeadPicForm.superclass.initComponent.call(this);
	}
});

Chenxin.FormCommon.UploadHeadPicForm=function(formID){
	return '<table class="tbl_f"><tr><th>上传头像：</th><td><input type="file" name="UpHeadPic" id="UpHeadPic"/></td><td><a style="color:#cc3300;" href="javascript:void(0);" onclick="useCamera()">使用摄像头</a></td></tr><tr><th colspan="3"><div id="avatar_editor" style="text-align:center;"></div></th></tr><tr><td colspan="3"><div style="float:right; margin-right:15px;"><a id="' + formID + '_cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></table>';
};